doctype html
html
  head

    title

    meta(http-equiv="Content-Type", content="text/html; charset=utf-8")
    meta(name="viewport", content="width=320, target-densitydpi=device-dpi")

    style(type='text/css').
      body { margin: 0; padding: 0 }
      body, * { font-family: "Helvetica Neue", Arial, Helvetica, sans-serif; -webkit-text-size-adjust: 90% }
      @media (max-width: 800px) {
        #background { background: #fff !important; padding: 0 !important }
      }
      pre { font-size: 12px; line-height: 18px; overflow: auto; white-space: pre; }
      code, pre, code *, pre * { font-family: Menlo, Monaco, Consolas, "Courier New", monospace; }

  body(style="margin: 0; padding: 0")
    div#background(style="background: #eee; padding: 20px")
      div(style="background: #fff; padding: 20px; width: 540px; max-width: 100%; color: #444; border-radius: 5px; margin: 0 auto")

        //- Header
        div(style="padding-bottom: 20px")
          div(style="border-top: 10px solid #{ color }; padding: 20px; background: #eee; border-radius: 4px; text-align: center")
            h1(style="font-weight: normal; margin: 0 0 12px; line-height: 1.3") #{ requestId }
            h2(style="font-weight: normal; margin: 0 0 21px; line-height: 1") #{ status }
            if singularityTaskLink
              a(style="background: #08c; color: #fff; padding: 10px 20px; display: inline-block; text-decoration: none; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; border-radius: 3px", href="#{ singularityTaskLink }") View task

        //- Status
        div(style="padding-bottom: 20px")
          div(style="padding-bottom: 12px; margin: 15px 0; border-bottom: 1px solid #eee")
            h3(style="margin: 0; font-size: 20px; line-height: 1") Status
          p
            if taskStateLost
              | This is likely an infrastructure issue. No action is required.
            if taskStateFinished
              if !requestAlwaysRunning
                | The task finished running and exited with a normal exit code. No action is required.
              else
                | The task finished running and exited with a normal exit code. Since this task was not part of a scheduled request, it is worth investigating whether this was the expected behavior. Often this means the task actually failed and exited with an incorrect exit code.
            if taskStateKilled
              | The task was killed by either Singularity, the OOM killer, or user action.
            if taskStateFailed
              | The task failed with a non-zero exit code. Consider investigating to see if there is an application level error.
            if taskStateRunning
              | The task has been running for #{ runTime }. Consider checking whether this task is running correctly.
              ul
                li This is a one-time notification about this task.
                li It was expected to run for a maximum of #{ expectedRunTime }.
                li This can be configured on a per-request basis with scheduledExpectedRuntimeMillis, otherwise it is calculated based on the schedule or historical average.
                li The warning threshold is #{ warningThreshold } of expectedRunTime. (part of global configuration.)
          if requestScheduled
            if !taskStateRunning
              if taskWillRetry
                p Singularity will retry the task #{ numRetries } times before it resumes on its normal schedule.
              if !taskWillRetry
                p Singularity will run the task again on its normal schedule.
          if requestOneOff
            p Singularity will not run your task again unless manually instructed.
          else if requestRunOnce
            p Singularity will not run your task again until it is deployed.
          else if !requestScheduled
            p Singularity will continue to restart your task immediately.
          if !taskStateFinished
            if !taskStateRunning
              if !taskRan
                p(style="margin-bottom: 0") <b>Recommended course of action: </b> None. Singularity was not able to launch this task on the desired agent. For further assistance email #{ adminEmails }.
              else
                if taskStateFailed
                  p(style="margin-bottom: 0") <b>Recommended course of action: </b> Check Singularity for logs or ssh into the agent.
                if taskStateLost
                  p(style="margin-bottom: 0") <b>Recommended course of action: </b> None. The agent process hosting the task or the underlying agent hardware likely failed. You may want to check the agent or monitoring systems as it is possible, though unlikely, that the task may still be running.

        //- History
        div(style="padding-bottom: 20px")
          div(style="padding-bottom: 12px; margin: 15px 0; border-bottom: 1px solid #eee")
            h3(style="margin: 0; font-size: 20px; line-height: 1") History
          table(style="border: 0; border-collapse: collapse; background: #eee")
            tr
              th(style="border: 0; border-collapse: collapse; padding: 12px; color: #444; border-bottom: 1px solid #ccc; text-align: left") Status
              th(style="border: 0; border-collapse: collapse; padding: 12px; color: #444; border-bottom: 1px solid #ccc; text-align: left") Message
              th(style="border: 0; border-collapse: collapse; padding: 12px; color: #444; border-bottom: 1px solid #ccc; text-align: left") Time
            each taskUpdate, i in taskUpdates
              tr
                td(style="border: 0; border-collapse: collapse; padding: 12px; color: #444")= taskUpdate.update
                td(style="border: 0; border-collapse: collapse; padding: 12px; color: #444")= taskUpdate.message
                td(style="border: 0; border-collapse: collapse; padding: 12px; color: #444")= taskUpdate.date

        //- Info
        div(style="padding-bottom: 20px")
          div(style="padding-bottom: 12px; margin: 15px 0; border-bottom: 1px solid #eee")
            h3(style="margin: 0; font-size: 20px; line-height: 1") Info
          dl
            dt(style="font-weight: bold; margin: 0 0 9px") Request ID
            dd(style="background: #eee; display: block; margin: 0 0 17px; padding: 10px 14px; border-radius: 3px") #{ requestId }
            dt(style="font-weight: bold; margin: 0 0 9px") Deploy ID
            dd(style="background: #eee; display: block; margin: 0 0 17px; padding: 10px 14px; border-radius: 3px") #{ deployId }
            dt(style="font-weight: bold; margin: 0 0 9px") Task ID
            dd(style="background: #eee; display: block; margin: 0 0 17px; padding: 10px 14px; border-radius: 3px") #{ taskId }
            dt(style="font-weight: bold; margin: 0 0 9px") Hostname of agent task ran on
            dd(style="background: #eee; display: block; margin: 0 0 17px; padding: 10px 14px; border-radius: 3px") #{ agentHostname }
            dt(style="font-weight: bold; margin: 0 0 9px") Directory
            dd(style="background: #eee; display: block; margin: 0 0 17px; padding: 10px 14px; border-radius: 3px") #{ taskDirectory }
            if extraCmdLineArguments
              dt(style="font-weight: bold; margin: 0 0 9px") Extra Cmd Line Arguments (for Task)
              dd(style="background: #eee; display: block; margin: 0 0 17px; padding: 10px 14px; border-radius: 3px")
                ul
                  each cmdLineArg, i in extraCmdLineArguments
                    li #{ cmdLineArg }

        //- Files
        div
          div(style="padding-bottom: 12px; margin: 15px 0; border-bottom: 1px solid #eee")
            h3(style="margin: 0; font-size: 20px; line-height: 1") Files
          dl(style="margin-bottom: 0")
            each log in logTails
              dt(style="font-weight: bold; margin: 0 0 9px")
                if log.link
                  a(href="#{ log.link }") #{ log.file }
                else
                  #{ log.file }
              dd(style="background: #eee; display: block; margin: 0 0 17px; padding: 10px 14px; border-radius: 3px")
                if log.log
                  pre(style="white-space: pre; margin: 0")
                    code(style="font-family: Menlo, Monaco, Consolas, Courier, monospace; white-space: pre;")
                      #{ log.log }
                else
                  | #{ log.path } not available. The task either did not start, output anything, or the agent hosting the log files was unavailable over http.

        //- Metadata
        if taskHasMetadata
          div(style="padding-bottom: 20px")
            div(style="padding-bottom: 12px; margin: 15px 0; border-bottom: 1px solid #eee")
              h3(style="margin: 0; font-size: 20px; line-height: 1") Metadata
            each taskMetadataElement, i in taskMetadata
              strong(style="margin: 0; margin-top: 5; line-height: 1")
                #{ taskMetadataElement.level } (#{ taskMetadataElement.type }) - #{ taskMetadataElement.date }
              if taskMetadataElement.user
                p
                  strong(style="margin: 0; line-height: 1") by
                  //- Note the extra space on the next line
                  |   #{ taskMetadataElement.user }
              div(style="background: #eee; display: block; margin: 0 0 17px; padding: 10px 14px; border-radius: 3px")
                p(style="margin: 0; margin-top: 5; line-height: 1") <b> #{ taskMetadataElement.title } </b>
                if taskMetadataElement.message
                  p #{ taskMetadataElement.message }
